package ch8recursion;

import java.awt.Point;
import java.util.ArrayList;

public class Ex2 {
	static ArrayList<Point> current_path = new ArrayList<Point>();
	
	public static void main(String[] argv) {
		getPaths(3, 3);
	}

	public static boolean getPaths(int x, int y) {
		Point p = new Point(x, y);
		current_path.add(p);
		if (0 == x && 0 == y) {
			for (Point point : current_path) {
				System.out.print("("+point.x+", "+point.y+") ");
			}
			System.out.println();
			current_path.remove(p);
			return true; // current_path
		}
		boolean success = false;
		if (x >= 1 && is_free(x - 1, y)) { // Try right
			success = getPaths(x - 1, y); // Free! Go right
		}
		if (y >= 1 && is_free(x, y - 1)) { // Try down
			success = getPaths(x, y - 1); // Free! Go down
		}
//		if (!success) {
			current_path.remove(p); // Wrong way!
//		}
		return success;
	}

	private static boolean is_free(int i, int j) {
		return true;
	}
}
